#include "bookmanage.h"
#include "ui_bookmanage.h"
#include"borrowerbookwidget.h"
#include"home.h"

#include <QPalette>

BookManage::BookManage(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::BookManage)
{
    ui->setupUi(this);
    //初始化窗口
    initWindow();
    //添加事件
    addEvents();
}
BookManage::~BookManage()
{
    delete ui;
}

//初始化窗口
void BookManage::initWindow(){
    this->resize(2200,1200);
    //将 mainLayout 这个布局管理器设置给 centralwidget。
    ui->centralwidget->setLayout(ui->mainLayout);

    ui->ButtonWidget->setLayout(ui->ButtonLayout);

    //添加图书归还界面
    returnBookWidget=new ReturnBook(this);
    ui->stackedWidget->addWidget(returnBookWidget);

    //添加图书借阅界面(暂时空白)
    borrowerBookWidget=new borrowerBookwidget();

    ui->stackedWidget->addWidget(borrowerBookWidget);

    //添加借阅历史界面
    historyBookWidget=new HistoryBook(this);
    ui->stackedWidget->addWidget(historyBookWidget);

    //设置初始界面为图书借阅界面(暂时空白)
    ui->stackedWidget->setCurrentWidget(borrowerBookWidget);
}
//添加事件
void BookManage::addEvents(){
    QObject::connect(ui->returnButton,&QPushButton::clicked,this,&BookManage::returnButtonEvent);
    QObject::connect(ui->borrowerBookButton,&QPushButton::clicked,this,&BookManage::borrowBookButtonEvent);
    QObject::connect(ui->bookReturnButton,&QPushButton::clicked,this,&BookManage::bookReturnButtonEvent);
    QObject::connect(ui->loanHistoryButton,&QPushButton::clicked,this,&BookManage::loanHistoryButtonEvent);
}
//返回按钮触发的事件
void BookManage::returnButtonEvent(){
    qDebug()<<"返回按钮按下";
}

//图书借阅按钮触发的事件
void BookManage::borrowBookButtonEvent(){
    qDebug()<<"图书借阅按钮按下";
    borrowerBookWidget->init();
    //切换到图书借阅界面
    ui->stackedWidget->setCurrentWidget(borrowerBookWidget);
}

//图书归还按钮触发的事件
void BookManage::bookReturnButtonEvent(){

    qDebug()<<"图书归还按钮按下";
    /*//重新初始化界面
    ui->stackedWidget->removeWidget(returnBookWidget);
    //添加图书归还界面
    returnBookWidget=new ReturnBook(this);
    ui->stackedWidget->addWidget(returnBookWidget);*/
    //切换到图书归还界面
    returnBookWidget->initWindow();
    ui->stackedWidget->setCurrentWidget(returnBookWidget);
}

//历史借阅按钮触发的事件
void BookManage::loanHistoryButtonEvent(){
    qDebug()<<"历史借阅按钮按下";
    historyBookWidget->initWindow();
    ui->stackedWidget->setCurrentWidget(historyBookWidget);
}

void BookManage::resizeEvent(QResizeEvent *event){
     qDebug()<<"窗口大小调整:"<<event->size();
}

void BookManage::on_returnButton_clicked()
{
  //点击返回
    this->hide();
    home*h=new home;
    h->show();


}
